package com.cfpamf.ms.insur.wx.request;

import com.cfpamf.ms.insur.wx.model.WxPayModel;
import com.cfpamf.ms.insur.wx.response.WxPayResponse;

import static com.cfpamf.ms.insur.wx.util.WXPayConstants.*;

/**
 * 微信支付 抽象请求类
 * Create By zhengjing on 2019-09-26 17:20
 */
public abstract class WxAbstractRequest<R extends WxPayModel, T extends WxPayResponse> implements WechatPayRequest<R, T> {

    protected R model;

    public WxAbstractRequest() {

    }

    public WxAbstractRequest(R model) {
        this.setModel(model);
    }

    public R getModel() {
        return this.model;
    }

    public void setModel(R model) {
        SignType signType = getSignType();
        if (SignType.MD5.equals(signType)) {
            model.setSignType(MD5);
        } else if (SignType.HMACSHA256.equals(signType)) {
            model.setSignType(HMACSHA256);
        } else {
            throw new RuntimeException(String.format("Invalid sign_type: %s", signType));
        }
        this.model = model;
    }
}
